<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="cloud" tagdir="/WEB-INF/tags/" %>

<!DOCTYPE HTML PUBtdC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<script type="text/javascript" src="<c:url value="/flashpaper/flexpaper.js" />"></script>
	<script type="text/javascript" src="<c:url value="/flashpaper/config.js" />"></script>
</head>

<body>
	<div class="wrapper">
	
		<div id="btnDiv">
			<a href="<c:url value="/docstore/openDocstore.do?parentId=${param.parentId}" />" class="button button-rounded button-flat-primary">返回</a>
			<a href="<c:url value="/download.action?fileName=${doc.attach.id}.${doc.attach.extendType}&realName=${doc.name}" />" class="button button-rounded button-flat-primary">下载文档</a>
		</div>
		
		<div class="name">${doc.name}</div>
		
        <div id="viewArea" class="doc-view">
        	<c:if test="${textContent != null}">
        		${textContent}
        	</c:if>
        </div>
		
		<div class="title">基本信息</div>
		
		<table class="detail-table">
			<tr>
				<td class="label-td">文件类型</td>
				<td class="half-td">${doc.attach.extendType}</td>
				<td class="label-td">文件大小</td>
				<td class="half-td"><cloud:fileSize size="${doc.attach.fileSize}" /></td>
			</tr>
			<tr>
				<td class="label-td">创建人</td>
				<td class="half-td"><cloud:user userId="${doc.creator}" /></td>
				<td class="label-td">创建时间</td>
				<td class="half-td"><cloud:time date="${doc.createTime}" /></td>
			</tr>
		</table>
		
		<cloud:note />
		
		<input id="entityId" type="hidden" value="${param.docId}" />
		<input id="extendFlag" type="hidden" value="<cloud:fileImg extend="${doc.attach.extendType}" />" />
	</div>
	
	<script>
		var extendFlag = $("#extendFlag").val().trim(), html = "";
		
		// if is image
		if(!extendFlag) {
			html += "<img src='" + top.basePath + "upload/" + "${doc.attach.id}" + "." + "${doc.attach.extendType}" + "' />";
		}
		// if is file that cann't preview
		else if(extendFlag == "file_bk") {
			html += "<div class='alert alert-info'>该文档不能在线浏览。</div>";
		}
		// if is text file
		else if(extendFlag == "txt_bk") {
			$("div.doc-view").addClass("doc-view-border");
		}
		// if is office or pdf file
		else {
			var doc = "${doc.attach.id}";
			
			_remoteCall("docdetail/getConvertStatus.do", {docId: doc}, function(status) {
				if(status == "Y") {
					initOnlineView(doc);
				} else {
					html += "<div class='alert alert-info'>该文档正在后台进行文档转换，请稍等会后再来浏览该文档。</div>";
				}
			}, false, true);
		}
		
		$("div.doc-view").append(html);
	</script>
</body>
</html>
